import router from "./router";
import store from "./store";

const whiteList = ["/login", "/register", "/forgetPasswd"];

const world = JSON.parse(localStorage.getItem("world"));
if (world != null) {
  store.state.world = world;
}

router.beforeEach((to, from, next) => {
  if (whiteList.indexOf(to.path) !== -1 || store.state.world.token != null) {
    next();
  } else {
    next("/login");
  }
});
